#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <stack>

using namespace std;

class Solution {
public:
    string simplifyPath(string path) {
        vector<string> stk;
        string pathNew = path + "/";
        while (pathNew.length() != 0) {
            auto pos = pathNew.find('/');
            if (pos != string::npos) {
                string strTmp = pathNew.substr(0, pos);
                SubStrStringProc(strTmp, stk);
                pathNew = pathNew.substr(pos + 1);
            }
        }

        string ret = "/";
        for (auto it = stk.begin(); it != stk.end(); it++) {
            ret += *it + "/";
        }

        if (ret.length() > 1 && ret.back() == '/') {
            ret.pop_back();
        }
        return ret;
    }

    void SubStrStringProc(string& str, vector<string>& stk)
    {
        // 过滤多余的 /
        if (str.empty()) {
            return;
        }

        // 过滤当前目录 .
        if (str == ".") {
            return;
        }

        if (str == "..") {
            if (!stk.empty()) {
                stk.pop_back();
            }
            return;
        }
        stk.push_back(str);
    }
};


int main()
{
    Solution s;
    string str = "/a/./b/../../c/";
    cout << s.simplifyPath(str) << endl;
    return 0;
}